package demo;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

/**
 * Created by lxji on 2017/9/19.
 */
public class SimpleCargoDemo {
    private static final String BASEURL = "http://api.test.56ctms.com";
    private static final String token = "e75fe624-eab6-4238-85f8-1cdb82d71568";

    public static void main(String[] args) throws IOException {
        HttpPost httpPost = new HttpPost(BASEURL + "/cargo/add" + "?access_token=" + token);

        JSONObject cargoRequest = new JSONObject();
        cargoRequest.put("orderNumber", "wmssn1235");
        cargoRequest.put("cargoNumber", "wmssnCargo123");


        StringEntity stringEntity = new StringEntity(cargoRequest.toJSONString(), ContentType.APPLICATION_JSON);
        httpPost.setEntity(stringEntity);
        httpPost.setHeader("Content-Type", "application/json; charset=utf-8");

        HttpClient httpClient = HttpClientBuilder.create().build();
        HttpResponse response = httpClient.execute(httpPost);
        String body = EntityUtils.toString(response.getEntity());
        JSONObject result = JSON.parseObject(body);
        System.out.println(result);
    }
}
